using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using WPFPractice.Utils;
using WPFPractice.ViewModels;
using WPFTemplateLib.WpfHelpers;

namespace WPFPractice.Windows
{
	public partial class WinSystemInfo : Window
	{
		public WinSystemInfo()
		{
			InitializeComponent();
			DataContext = new SystemInfoViewModel();
		}
	}
}

namespace WPFPractice.ViewModels
{
	public class SystemInfoViewModel : MyBindableBase
	{
		#region 绑定

		public double DpiValue { get; private set; }

		public string ScreensInfo { get; set; }

		public string CurrentScreenInfo { get; set; }

		#endregion

		#region 命令

		#region [命令] 刷新
		private ICommand _RefreshCmd;
		public ICommand RefreshCmd => _RefreshCmd ??= new RelayCommand<Window>(ExecuteRefreshCmd);
		private void ExecuteRefreshCmd(Window win)
		{
			Refresh(win);
		}
		#endregion

		#endregion

		#region 方法

		/// <inheritdoc />
		protected override void InitDataAfterConstruction()
		{
			base.InitDataAfterConstruction();
			Console.WriteLine("演示获取系统信息");
		}

		/// <summary>
		/// 刷新
		/// </summary>
		/// <param name="win">窗口</param>
		private void Refresh(Window win)
		{
			//DpiScale dpi = VisualTreeHelper.GetDpi(win);
			//DpiValue = dpi.DpiScaleX;

			DpiValue = ScreenHelper.GetScalingRatio();
			var screens = WpfScreen.AllScreens().ToList();
			ScreensInfo = string.Join(Environment.NewLine, screens);

			CurrentScreenInfo = WpfScreen.GetScreenFrom(win).ToString();
		}

		#endregion
	}
}
